/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.unesp.rc.rafaelt.model.bean;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import com.sun.istack.NotNull;

/**
 *
 * @author rafaelt
 */
@Entity
@Table(name = "mark")
@XmlRootElement(name = "mark")
/*@NamedQueries({
    @NamedQuery(name = "Mark.findAll", query = "SELECT m FROM Mark m"),
    @NamedQuery(name = "Mark.findByStudentidStudent", query = "SELECT m FROM Mark m WHERE m.markPK.studentidStudent = :studentidStudent"),
    @NamedQuery(name = "Mark.findBySubjectidSubject", query = "SELECT m FROM Mark m WHERE m.markPK.subjectidSubject = :subjectidSubject"),
    @NamedQuery(name = "Mark.findByDate", query = "SELECT m FROM Mark m WHERE m.date = :date"),
    @NamedQuery(name = "Mark.findByMark", query = "SELECT m FROM Mark m WHERE m.mark = :mark")})

@NamedQueries({
    @NamedQuery(name=Mark.QUERY_I,
            query=""),
    @NamedQuery(name=Mark.QUERY_II,
            query=""),
    @NamedQuery(name=Mark.QUERY_III,
            query="")
})
*/
public class Mark implements Serializable {
	
    private static final long serialVersionUID = 1L;
    
    /*
    public static final String QUERY_I = "findQueryI";
    public static final String QUERY_II = "findQueryII";
    public static final String QUERY_III = "findQueryIII";
    */    
    
    @EmbeddedId
    protected MarkPK markPK;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "date")
    @Temporal(TemporalType.DATE)
    private Date date;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "mark")
    private double mark;
    
    @JoinColumn(name = "subject_idSubject", referencedColumnName = "idSubject", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Subject subject;
    
    @JoinColumn(name = "student_idStudent", referencedColumnName = "idStudent", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Student student;

    public Mark() {
    }

    public Mark(MarkPK markPK) {
        this.markPK = markPK;
    }

    public Mark(MarkPK markPK, Date date, double mark) {
        this.markPK = markPK;
        this.date = date;
        this.mark = mark;
    }

    public Mark(long studentidStudent, long subjectidSubject) {
        this.markPK = new MarkPK(studentidStudent, subjectidSubject);
    }

    public MarkPK getMarkPK() {
        return markPK;
    }

    public void setMarkPK(MarkPK markPK) {
        this.markPK = markPK;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public double getMark() {
        return mark;
    }

    public void setMark(double mark) {
        this.mark = mark;
    }

    public Subject getSubject() {
        return subject;
    }

    public void setSubject(Subject subject) {
        this.subject = subject;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (markPK != null ? markPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Mark)) {
            return false;
        }
        Mark other = (Mark) object;
        if ((this.markPK == null && other.markPK != null) || (this.markPK != null && !this.markPK.equals(other.markPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.unesp.rc.model.bean.Mark[ markPK=" + markPK + " ]";
    }
    
}
